package com.dddpeter.app.object;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.log4j.Logger;

/** 
* @ClassName: BaseEntity 
* @Description: 实体类基类
* @author Peter Lee
* @date 2014年8月11日 下午2:07:17 
*  
*/
public class BaseEntity {
	public String toString() {
		Field[] fields = this.getClass().getDeclaredFields();
		StringBuilder sbuilder = new StringBuilder();
		Logger log=Logger.getLogger(this.getClass());
		for (int i = 0; i < fields.length; i++) {
			String fieldName = fields[i].getName();
			String methodName = "get" + fieldName.substring(0, 1).toUpperCase()
					+ fieldName.substring(1);
			try {
				Method method = this.getClass().getMethod(methodName,
						new Class[]{});
				Object value = method.invoke(this, new Object[]{});
				sbuilder.append(fieldName + ":");
				sbuilder.append(value + "  ");
			} catch (SecurityException e) {
				
				
				log.error(e.getMessage());
			} catch (NoSuchMethodException e) {
				
				
				log.error(e.getMessage());
			} catch (IllegalArgumentException e) {
				
				
				log.error(e.getMessage());
			} catch (IllegalAccessException e) {
				
				
				log.error(e.getMessage());
			} catch (InvocationTargetException e) {
				
				
				log.error(e.getMessage());
			}
		}
		return sbuilder.toString();
	}

}
